package com.ruoyi.web.controller.qsng;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.qsng.domain.KLearningHome;
import com.ruoyi.qsng.service.IKLearningHomeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 学习之家Controller
 *
 * @author kanglou
 * @date 2023-06-07
 */
@RestController
@RequestMapping("/qsng/home")
@Api(tags = "pc--学习之家Controller")
public class KLearningHomeController extends BaseController {
    @Autowired
    private IKLearningHomeService kLearningHomeService;

    /**
     * 查询学习之家列表
     */
    @PreAuthorize("@ss.hasPermi('qsng:home:list')")
    @GetMapping("/list")
    @ApiOperation(value = "查询学习之家列表")
    public TableDataInfo list(KLearningHome kLearningHome) {
        startPage();
        List<KLearningHome> list = kLearningHomeService.selectKLearningHomeList(kLearningHome);
        return getDataTable(list);
    }

    /**
     * 导出学习之家列表
     */
    @PreAuthorize("@ss.hasPermi('qsng:home:export')")
    @Log(title = "学习之家", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation(value = "导出学习之家列表")
    public void export(HttpServletResponse response, KLearningHome kLearningHome) {
        List<KLearningHome> list = kLearningHomeService.selectKLearningHomeList(kLearningHome);
        ExcelUtil<KLearningHome> util = new ExcelUtil<KLearningHome>(KLearningHome.class);
        util.exportExcel(response, list, "学习之家数据");
    }

    /**
     * 获取学习之家详细信息
     */
    @PreAuthorize("@ss.hasPermi('qsng:home:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation(value = "获取学习之家详细信息")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(kLearningHomeService.selectKLearningHomeById(id));
    }

    /**
     * 新增学习之家
     */
    @PreAuthorize("@ss.hasPermi('qsng:home:add')")
    @Log(title = "学习之家", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation(value = "新增学习之家")
    public AjaxResult add(@RequestBody KLearningHome kLearningHome) {
        return toAjax(kLearningHomeService.insertKLearningHome(kLearningHome));
    }

    /**
     * 修改学习之家
     */
    @PreAuthorize("@ss.hasPermi('qsng:home:edit')")
    @Log(title = "学习之家", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation(value = "修改学习之家")
    public AjaxResult edit(@RequestBody KLearningHome kLearningHome) {
        return toAjax(kLearningHomeService.updateKLearningHome(kLearningHome));
    }

    /**
     * 删除学习之家
     */
    @PreAuthorize("@ss.hasPermi('qsng:home:remove')")
    @Log(title = "学习之家", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation(value = "删除学习之家")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(kLearningHomeService.deleteKLearningHomeByIds(ids));
    }
}
